package com.suray.basic.wcs.plc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.basic.wcs.plc.core.Plc;
import com.suray.basic.wcs.plc.entity.PlcDeviceDB;
import com.suray.basic.wcs.plc.enums.*;
import com.suray.basic.wcs.plc.mapper.PlcDeviceDBMapper;
import com.suray.basic.wcs.plc.pojo.*;
import com.suray.basic.wcs.plc.pojo.oper.*;
import com.suray.basic.wcs.plc.pojo.oper.single.*;
import com.suray.basic.wcs.plc.pojo.oper.single.lifter.LifterStationOper;
import com.suray.basic.wcs.plc.pojo.oper.single.lifter.LifterSystemOper;
import com.suray.basic.wcs.plc.service.IPlcDeviceDBService;
import com.suray.basic.wcs.plc.utils.FoldingMachineAction;
import com.suray.basic.wcs.plc.utils.PlcDeviceProcess;
import com.suray.basic.wcs.utils.Coord;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhr
 * @since 2019-06-26
 */
@Service
public class PlcDeviceDBServiceImpl extends ServiceImpl<PlcDeviceDBMapper, PlcDeviceDB> implements IPlcDeviceDBService {

    @Resource
    private PlcDeviceDBMapper plcdevicedbMapper;

    /**
     * @return List<Plcdevicedb>
     * @Description:根据设备类型查询plc设备
     * @author rbj
     */
    @Override
    public List<PlcDeviceDB> queryPlcDevices(List<Integer> deviceType) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(PlcDeviceDB::getDeviceType, deviceType);
        return this.list(queryWrapper);
    }

    /**
     * @return List<Plcdevicedb>
     * @Description:查询plc设备：输送线、提升机 <库口配置专用 添加调用小车数据>
     * @author rbj
     */
    @Override
    public List<PlcDeviceDB> queryPlcDevices() {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<PlcDeviceDB>();
        queryWrapper.lambda()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.CHAIN_STATION.getVal())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.PANASONIC_LIFT.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.SIEMENS_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TAMAGAWA_LIFTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTOMATIC_LIFTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTO_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TOOTH_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.MONOMER_CONVEYOR.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTO_TRAVERSING.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TRANS_PLANTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.FOLDING_MACHINE.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.FORK_LIFTER.getTypeNum());
        List<PlcDeviceDB> plcDevList = this.list(queryWrapper);

        PlcDeviceDB plcdevicedb;
        for (PlcDeviceProcess plcDeviceProcess : PlcDeviceProcess.values()) {
            if (plcDeviceProcess == PlcDeviceProcess.INVALID) {
                continue;
            }

            plcdevicedb = new PlcDeviceDB();
            plcdevicedb.setDeviceId(plcDeviceProcess.getId());
            plcdevicedb.setDeviceName(plcDeviceProcess.getDes());
            plcDevList.add(plcdevicedb);
        }
        for (PlcDeviceDB plcDevice : plcDevList) {
            if (plcDevice.getDeviceType() != null &&
                    (
                            plcDevice.getDeviceType() == PlcDeviceType.PANASONIC_LIFT.getTypeNum()
                                    || plcDevice.getDeviceType() == PlcDeviceType.SIEMENS_HOIST.getTypeNum()
                                    || plcDevice.getDeviceType() == PlcDeviceType.TAMAGAWA_LIFTER.getTypeNum()
                                    || plcDevice.getDeviceType() == PlcDeviceType.AUTOMATIC_LIFTER.getTypeNum()
                                    || plcDevice.getDeviceType() == PlcDeviceType.FORK_LIFTER.getTypeNum()
                    )
            ) {
                plcDevice.setDeviceName(plcDevice.getDeviceName() + Location.parseLocationCode(plcDevice.getLocation()).getDescription());

            }
        }
        return plcDevList;
    }

    /**
     * @return List<Plcdevicedb>
     * @Description:查询plc设备：输送线、提升机 <库口配置专用 添加调用小车数据>
     * @author rbj
     */
    @Override
    public List<PlcDeviceDB> queryPlcConvDevices() {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<PlcDeviceDB>();
        queryWrapper.lambda()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.CHAIN_STATION.getVal())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTO_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TOOTH_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.MONOMER_CONVEYOR.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTO_TRAVERSING.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TRANS_PLANTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.FOLDING_MACHINE.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.FORK_LIFTER.getTypeNum());
        List<PlcDeviceDB> plcDevList = this.list(queryWrapper);
        return plcDevList;
    }

    /**
     * @return Plcdevicedb
     * @Description:根据id查询plc设备
     * @author rbj
     */
    @Override
    public PlcDeviceDB getPlcDevById(Integer id) {
        PlcDeviceDB plcdevicedb = this.getById(id);
        return plcdevicedb;
    }

    @Override
    public boolean addPlcDevice(PlcDeviceDB plcdevicedb) {
        return this.save(plcdevicedb);
    }

    @Override
    public int changePlc(PlcDeviceDB plcdevicedb) {
        return plcdevicedbMapper.updateById(plcdevicedb);
    }

    @Override
    public boolean checkPlcDeviceName(String plcName, Integer plcId) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(PlcDeviceDB::getPlcId, plcId).eq(PlcDeviceDB::getDeviceName, plcName);
        List<PlcDeviceDB> plcDeviceList = this.list(queryWrapper);
        return plcDeviceList.size() == 1;
    }

    /**
     * plc修改禁用状态的时候同步修改PlcDevice的禁用状态
     *
     * @return
     */
    @Override
    public int updatePlcDeviceByPlcId(PlcDeviceDB plcDeviceDB, String status) {
        plcDeviceDB.setStatus(status);
        return plcdevicedbMapper.updateById(plcDeviceDB);
    }

    @Override
    public boolean checkPlcDeviceName(PlcDeviceDB plcdevicedb) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        if (plcdevicedb.getDeviceId() == null) {// 新增
            queryWrapper.lambda().eq(PlcDeviceDB::getDeviceName, plcdevicedb.getDeviceName()).eq(PlcDeviceDB::getPlcId, plcdevicedb.getPlcId());
            return this.count(queryWrapper) > 0;
        }
        // 修改
        PlcDeviceDB plcDeviceDB1 = this.getById(plcdevicedb.getDeviceId());
        if (plcDeviceDB1.getDeviceName() != null && plcDeviceDB1.getDeviceName().equals(plcdevicedb.getDeviceName())) {
            return false;
        } else {
            queryWrapper.lambda().eq(PlcDeviceDB::getDeviceName, plcdevicedb.getDeviceName()).eq(PlcDeviceDB::getPlcId, plcdevicedb.getPlcId());
            return this.count(queryWrapper) > 0;
        }
    }

    /**
     * 为true时编号重复
     *
     * @param plcdevicedb
     * @return
     */
    @Override
    public boolean checkPlcDeviceNo(PlcDeviceDB plcdevicedb) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        if (plcdevicedb.getDeviceId() == null) {// 新增
            queryWrapper.lambda().eq(PlcDeviceDB::getDeviceNo, plcdevicedb.getDeviceNo()).eq(PlcDeviceDB::getPlcId, plcdevicedb.getPlcId());
            return this.count(queryWrapper) > 0;
        }
        // 修改
        PlcDeviceDB plcDeviceDB1 = this.getById(plcdevicedb.getDeviceId());
        if (plcDeviceDB1.getDeviceNo() != null && plcDeviceDB1.getDeviceNo().equals(plcdevicedb.getDeviceNo())) {
            return false;
        } else {
            queryWrapper.lambda().eq(PlcDeviceDB::getDeviceNo, plcdevicedb.getDeviceNo()).eq(PlcDeviceDB::getPlcId, plcdevicedb.getPlcId());
            return this.count(queryWrapper) > 0;
        }
    }

    @Override
    public List<PlcDeviceDB> getPlcByType(int deviceType) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(PlcDeviceDB::getDeviceType, deviceType);
        return this.list(queryWrapper);
    }

    @Override
    public List<PlcDeviceDB> deletePlcDevice(List<Integer> deviceIdList) {
        plcdevicedbMapper.deleteBatchIds(deviceIdList);
        return plcdevicedbMapper.selectBatchIds(deviceIdList);
    }

    /**
     * 根据类型查询设备
     *
     * @param deviceDB
     * @return
     */
    @Override
    public List<PlcDeviceDB> findByType(PlcDeviceType deviceDB) {
        List<PlcDeviceDB> devicedbs = this.list(new QueryWrapper<PlcDeviceDB>().lambda().eq(PlcDeviceDB::getDeviceType, deviceDB));
        return devicedbs;
    }

    /**
     * @return PlcDeviceDB
     * @Description:根据设备编号查询plc设备
     * @author rbj
     */

    @Override
    public PlcDeviceDB queryPlcdevByDeviceId(Integer deviceId) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<PlcDeviceDB>();
        queryWrapper.lambda().eq(PlcDeviceDB::getDeviceId, deviceId);
        PlcDeviceDB plcDev = this.getOne(queryWrapper);
        return plcDev;
    }

    @Override
    public PlcDeviceDB getSystemByPlcId(Integer plcId) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<PlcDeviceDB>();
        queryWrapper.lambda().eq(PlcDeviceDB::getPlcId, plcId).eq(PlcDeviceDB::getDeviceType,
                PlcDeviceType.SYSTEM.getTypeNum());
        PlcDeviceDB plcdevicedb = this.getOne(queryWrapper);
        return plcdevicedb;
    }

    /**
     * @return List<PlcDeviceDB>
     * @Description:查询
     * @author rbj
     */
    @Override
    public List<PlcDeviceDB> queryLiftList() {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(PlcDeviceDB::getLocation, Location.INSIDE.getCode())
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.PANASONIC_LIFT.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getLocation, Location.INSIDE.getCode())
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.SIEMENS_HOIST.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getLocation, Location.INSIDE.getCode())
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.TAMAGAWA_LIFTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getLocation, Location.INSIDE.getCode())
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.AUTOMATIC_LIFTER.getTypeNum())
                .or()
                .eq(PlcDeviceDB::getLocation, Location.INSIDE.getCode())
                .eq(PlcDeviceDB::getDeviceType, PlcDeviceType.FORK_LIFTER.getTypeNum());
        List<PlcDeviceDB> liftList = list(queryWrapper);
        return liftList;
    }


    @Override
    public List<PlcDeviceDB> selectDevsByCondtion(PlcDeviceDB plcdeviceDB) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>(plcdeviceDB);
        List<PlcDeviceDB> plcDeviceDBList = plcdevicedbMapper.selectList(queryWrapper);
        return plcDeviceDBList;
    }

    @Override
    public int deletePlcDevByIds(Long[] deviceId) {
        return plcdevicedbMapper.deleteBatchIds(Arrays.asList(deviceId));
    }

    @Override
    public PlcDeviceDB selectPlcDevById(Long deviceId) {
        return plcdevicedbMapper.selectById(deviceId);
    }

    @Override
    public HandleDishTemp plcDishDeviceR(String deviceName) {
        DismountingDiskMachineOper diskMachineOper = (DismountingDiskMachineOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleDishTemp dishTemp = new HandleDishTemp();
        if (StringUtils.isEmpty(deviceName) || diskMachineOper == null) {
            dishTemp.setReadyState("离线");
            return dishTemp;
        }
        dishTemp.setReadyState("在线");
        dishTemp.setPalletNo(Integer.toString(diskMachineOper.getPalletNo()));
        dishTemp.setEmptyPallet(diskMachineOper.isEmptyPallet() ? "是" : "否");
        dishTemp.setPalletNum(Integer.toString(diskMachineOper.getPalletNum()));
        dishTemp.setPalletExist(diskMachineOper.isPalletExist() ? "有货" : "无货");
        dishTemp.setLiftRuning(diskMachineOper.isLiftRuning() ? "运行" : "停止");
        dishTemp.setLiftError(diskMachineOper.isLiftError() ? "故障" : "无故障");
        dishTemp.setLeftForkRuning(diskMachineOper.isLeftForkRuning() ? "运行" : "停止");
        dishTemp.setLeftForkError(diskMachineOper.isLeftForkError() ? "故障" : "无故障");
        dishTemp.setRightForkRuning(diskMachineOper.isRightForkRuning() ? "运行" : "停止");
        dishTemp.setRightForkError(diskMachineOper.isRightForkError() ? "故障" : "无故障");
        dishTemp.setChainRuning(diskMachineOper.isChainRuning() ? "运行" : "停止");
        dishTemp.setChainError(diskMachineOper.isChainError() ? "故障" : "无故障");
        dishTemp.setUpperLimit(diskMachineOper.isUpperLimit() ? "到位" : "未到位");
        dishTemp.setMedianLimit(diskMachineOper.isMedianLimit() ? "到位" : "未到位");
        dishTemp.setLowerLimit(diskMachineOper.isLowerLimit() ? "到位" : "未到位");
        dishTemp.setLeftForkExtensionLimit(diskMachineOper.isLeftForkExtensionLimit() ? "到位" : "未到位");
        dishTemp.setLeftForkShrinkageLimit(diskMachineOper.isLeftForkShrinkageLimit() ? "到位" : "未到位");
        dishTemp.setRightForkExtensionLimit(diskMachineOper.isRightForkExtensionLimit() ? "到位" : "未到位");
        dishTemp.setRightForkShrinkageLimit(diskMachineOper.isRightForkShrinkageLimit() ? "到位" : "未到位");
        dishTemp.setDeviceName(deviceName);
        return dishTemp;
    }

    /**
     * 工位信息数据
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleChainStatus plcChainStationDeviceR(String deviceName) {
        HandleChainStatus chainStatus = new HandleChainStatus();
        chainStatus.setDeviceName(deviceName);
        StationOper stationOper = (StationOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || stationOper == null) {
            chainStatus.setReadyState("离线");
            return chainStatus;
        }
        chainStatus.setReadyState("在线");
        chainStatus.setChainBreakStatus((stationOper.isError() ? "故障" : "无效"));
        chainStatus.setChainRunStatus((stationOper.isRunIng() ? "运行中" : "未运行"));
        chainStatus.setIsHaveCargo((stationOper.isPalletExist() ? "有货" : "无货"));
        chainStatus.setChainPalletNo("" + stationOper.getPalletNo());
        chainStatus.setCanGet(stationOper.isCanGet() ? "可取" : "不可取");
        chainStatus.setCanPut(stationOper.isCanPut() ? "可放" : "不可放");
        return chainStatus;
    }

    @Override
    public int updateDeviceTask(long deviceId, int taskNo) {
        LambdaUpdateWrapper<PlcDeviceDB> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(PlcDeviceDB::getTaskNo, taskNo);
        updateWrapper.eq(PlcDeviceDB::getDeviceId, deviceId);
        return plcdevicedbMapper.update(null, updateWrapper);
    }

    @Override
    public int clearDeviceTask(long deviceId) {
        LambdaUpdateWrapper<PlcDeviceDB> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(PlcDeviceDB::getTaskNo, 0);
        updateWrapper.eq(PlcDeviceDB::getDeviceId, deviceId);
        return plcdevicedbMapper.update(null, updateWrapper);
    }

    /**
     * 外形检测信息
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleShape plcShapeDeviceR(String deviceName) {
        ShapeDetectorOper so = (ShapeDetectorOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleShape handleShape = new HandleShape();
        handleShape.setDeviceName(deviceName);
        if (StringUtils.isEmpty(deviceName) || so == null) {
            handleShape.setReadyState("离线");
            return handleShape;
        }
        String highType;
        String result = "无";
        switch (so.getHighType()) {
            case 1:
                highType = "一类高度";
                break;
            case 2:
                highType = "二类高度";
                break;
            case 3:
                highType = "三类高度";
                break;
            default:
                highType = "无效高度";
                break;
        }
        switch (so.getResult()) {
            case 1:
                result = "合格";
                break;
            case 2:
                result = "不合格";
                break;
            default:
                highType = "无效数据";
                break;
        }
        handleShape.setReadyState("在线");
        handleShape.setShapeResultFinal(result);
        handleShape.setCargoHighType(highType);
        handleShape.setFrontOver((so.isFrontTransfinite() ? "超限" : "未超限"));
        handleShape.setQueenOver((so.isAfterTransfinite() ? "超限" : "未超限"));
        handleShape.setLeftOver((so.isLeftTransfinite() ? "超限" : "未超限"));
        handleShape.setRightOver((so.isRightTransfinite() ? "超限" : "未超限"));
        handleShape.setHighOver((so.isHighTransfinite() ? "超限" : "未超限"));
        return handleShape;
    }

    /**
     * 称重设备信息
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleWeight plcWeightDeviceR(String deviceName) {
        WeightingEquipmentOper weightOper = (WeightingEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleWeight handleWeight = new HandleWeight();
        handleWeight.setDeviceName(deviceName);
        if (StringUtils.isEmpty(deviceName) || weightOper == null) {
            handleWeight.setReadyState("离线");
            return handleWeight;
        }
        handleWeight.setReadyState("在线");
        handleWeight.setWeightFlag(weightOper.isCanRead() ? "数据可读" : "数据不可读");
        handleWeight.setWeightData(((double) Long.parseLong("" + weightOper.getWeightData())) / 10);
        return handleWeight;
    }

    /**
     * 单体输送线 + 外形检测
     *
     * @param deviceId
     * @return
     */
    @Override
    public HandleShapeConveyor plcShapeConveyorDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        ShapeConveyorOper shapeConveyorOper = (ShapeConveyorOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleShapeConveyor hsc = new HandleShapeConveyor();
        hsc.setDeviceId(deviceId);
        hsc.setDeviceName(plcDeviceDB.getDeviceName());
        if (shapeConveyorOper == null) {
            hsc.setReadyState("离线");
            return hsc;
        }
        hsc.setReadyState(shapeConveyorOper.getPlc().getPlcStatus().getDescription());
        //设备类型
        hsc.setDeviceType(shapeConveyorOper.getCurrentDeviceType() == 3 ? "单体输送线+外形检测" : "未知");
        //设备位移量
        hsc.setMovement(Integer.toString(shapeConveyorOper.getMovement()));
        //输送线自动速度
        hsc.setConveyorAutoSpeed(Integer.toString(shapeConveyorOper.getConveyorAutoSpeed()));
        //输送线自动加速时间
        hsc.setConveyorAutoAcc(Integer.toString(shapeConveyorOper.getConveyorAutoAcc()));
        //输送线自动减速时间
        hsc.setConveyorAutoDec(Integer.toString(shapeConveyorOper.getConveyorAutoDec()));
        //输送线手动速度
        hsc.setConveyorManualSpeed(Integer.toString(shapeConveyorOper.getConveyorManualSpeed()));
        //输送线手动加速时间
        hsc.setConveyorManualAcc(Integer.toString(shapeConveyorOper.getConveyorManualAcc()));
        //输送线手动减速时间
        hsc.setConveyorManualDec(Integer.toString(shapeConveyorOper.getConveyorManualDec()));
        //单体设备运行（含自动门，翻转机构）
        hsc.setTaskAction(Integer.toString(shapeConveyorOper.getTaskAction()));
        //故障清除
        hsc.setClearError(shapeConveyorOper.isClearError() ? "故障清除" : "无");
        //系统急停
        hsc.setStopState(shapeConveyorOper.isStopState() ? "急停" : "未急停");
        //系统手动模式/自动本地
        String mode = "未知";
        if (shapeConveyorOper.isControllerMode()) {
            mode = "自动";
        } else {
            mode = "手动";
        }
        hsc.setControllerMode(mode);
        //手动输送线正转
        hsc.setManualForward(shapeConveyorOper.isManualForward() ? "运行中" : "未运行");
        //手动输送线反转
        hsc.setManualReverse(shapeConveyorOper.isManualReverse() ? "运行中" : "未运行");
        //WCS可控
        hsc.setIsControl(shapeConveyorOper.isControl() ? "就绪" : "未就绪");
        //设备正在运行中
        hsc.setDeviceState(shapeConveyorOper.isRunning() ? "运行中" : "未运行");
        //故障报警状态
        hsc.setErrorState(shapeConveyorOper.isErrorState() ? "故障" : "正常");
        //镜反光电1
        hsc.setSignal1(shapeConveyorOper.isInCargoSignalValid() ? "有信号" : "无信号");
        //镜反光电2
        hsc.setSignal2(shapeConveyorOper.isOutCargoSignalValid() ? "有信号" : "无信号");
        // 入库信号
        hsc.setAskInCargo(shapeConveyorOper.getIfAskInCargo() ? "有信号" : "无信号");
        //货物上超限报警
        hsc.setCargoUpAlarm(shapeConveyorOper.isCargoUpAlarm() ? "报警" : "正常");
        //货物左超宽报警
        hsc.setCargoLeftAlarm(shapeConveyorOper.isCargoLeftAlarm() ? "报警" : "正常");
        //货物右超宽报警
        hsc.setCargoRightAlarm(shapeConveyorOper.isCargoRightAlarm() ? "报警" : "正常");
        //货物前超限报警
        hsc.setCargoBeforeAlarm(shapeConveyorOper.isCargoBeforeAlarm() ? "报警" : "正常");
        //货物后超限报警
        hsc.setCargoAfterAlarm(shapeConveyorOper.isCargoAfterAlarm() ? "报警" : "正常");
        //托盘无货物报警
        hsc.setPalletEmptyAlarm(shapeConveyorOper.isPalletEmptyAlarm() ? "报警" : "正常");
        //高度1检测
        hsc.setHeight1(shapeConveyorOper.isHeight1() ? "有" : "无");
        //高度2检测
        hsc.setHeight2(shapeConveyorOper.isHeight2() ? "有" : "无");
        //高度3检测
        hsc.setHeight3(shapeConveyorOper.isHeight3() ? "有" : "无");
        //故障码
        hsc.setErrorInfo(Integer.toString(shapeConveyorOper.getErrorInfo()));
        //校准位
        hsc.setCheckNo(Integer.toString(shapeConveyorOper.getCheckNo()));
        //当前设备类型
        hsc.setCurrentDeviceType(SinglePlcDeviceType.parseValue(shapeConveyorOper.getCurrentDeviceType()).toString());
        hsc.setDeviceDes(shapeConveyorOper.getStatus());
        //任务号
        hsc.setTaskNo(shapeConveyorOper.getTaskNo());
        hsc.setStartNo(shapeConveyorOper.getTaskStartLocation());
        hsc.setEndNo(shapeConveyorOper.getTaskEndLocation());
        return hsc;
    }


    @Override
    public HandleScanOper plcScanDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        ScanOper scanOper = (ScanOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleScanOper scan = new HandleScanOper();
        scan.setDeviceName(plcDeviceDB.getDeviceName());
        scan.setDeviceId(deviceId);
        if (scanOper == null) {
            scan.setReadyState("离线");
            return scan;
        }
        scan.setReadyState(scanOper.getPlc().getPlcStatus().getDescription());
        scan.setIsCanRead(scanOper.isScanCanRead() ? "可读" : "不可读");
        String barCode = scanOper.getCodeData();
        if (StringUtils.isEmpty(barCode)) {
            scan.setBarcode("条码异常/读取不到条码");
        } else {
            scan.setBarcode(barCode.trim());
        }
        scan.setRes(scanOper.getPlcStatusStr());
        return scan;
    }
    /**
     * 扫码器数据信息
     *
     * @param deviceName
     * @return
     */
    @Override
    public ScannerHandleBean readBarCode(String deviceName) {
        SweepCodeEquipmentOper equipmentOper = (SweepCodeEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        ScannerHandleBean scannerHandleBean = new ScannerHandleBean();
        scannerHandleBean.setDeviceName(deviceName);
        if (deviceName.isEmpty() || equipmentOper == null) {
            scannerHandleBean.setReadyState("离线");
            return scannerHandleBean;
        }
        try {
            String barCode = equipmentOper.getCodeData();
            scannerHandleBean.setCanRead(equipmentOper.isCanRead() ? "可读" : "不可读");
            scannerHandleBean.setReadyState("在线");
            if (StringUtils.isEmpty(barCode)) {
                scannerHandleBean.setBarcodeStr("条码异常/读取不到条码");
            } else {
                scannerHandleBean.setBarcodeStr(barCode.trim());
            }
        } catch (Exception e) {
            log.error("点位配置异常!", e);
            scannerHandleBean.setReadyState("点位配置异常！" + e.getMessage());
        }
        return scannerHandleBean;
    }

    /**
     * 移栽机工位信息
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleTransplanter plcTransPlanterDeviceR(String deviceName) {
        TransplanterOper transplanterOper = (TransplanterOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleTransplanter handleTransplanter = new HandleTransplanter();
        handleTransplanter.setDeviceName(transplanterOper.getDeviceName());
        if (transplanterOper == null) {
            handleTransplanter.setReadyState("离线");
            return handleTransplanter;
        }
        handleTransplanter.setTaskNo(transplanterOper.getPalletNo() + "");
        handleTransplanter.setIsHaveCargo(transplanterOper.isPalletExist() ? "有货" : "无货");
        handleTransplanter.setUpRunStatus(transplanterOper.isRunStatus() ? "运行" : "停止");
        handleTransplanter.setUpBreakStatus(transplanterOper.isError() ? "故障" : "无故障");
        handleTransplanter.setChainBreakStatus(transplanterOper.isError2() ? "故障" : "无故障");
        handleTransplanter.setChainRunStatus(transplanterOper.isRunStatus2() ? "运行" : "停止");
        handleTransplanter.setHighLocation(transplanterOper.isUpperLimit() ? "到位" : "未到位");
        handleTransplanter.setLowLocation(transplanterOper.isLowerLimit() ? "到位" : "未到位");
        handleTransplanter.setDeviceName(deviceName);
        handleTransplanter.setReadyState("在线");
        return handleTransplanter;
    }

    /**
     * 自动升降机
     *
     * @param deviceId
     * @return
     */
    @Override
    public HandleAutoHoistOper plcAutoHoistDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        AutoHoistOper autoHoistOper = (AutoHoistOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleAutoHoistOper handleAutoHoistOper = new HandleAutoHoistOper();
        handleAutoHoistOper.setDeviceId(deviceId);
        handleAutoHoistOper.setDeviceName(plcDeviceDB.getDeviceName());
        if (autoHoistOper == null) {
            handleAutoHoistOper.setReadyState("离线");
            return handleAutoHoistOper;
        }
        handleAutoHoistOper.setReadyState(autoHoistOper.getPlc().getPlcStatus().getDescription());
        //设备类型
        handleAutoHoistOper.setDeviceType((autoHoistOper.getCurrentDeviceType() == 8 ? "自动升降机" : "未知"));
        //设备位移量
        handleAutoHoistOper.setMovement(Integer.toString(autoHoistOper.getMovement()));
        //升降自动速度
        handleAutoHoistOper.setLiftAutoSpeed(Integer.toString(autoHoistOper.getLiftAutoSpeed()));
        //升降自动加速时间
        handleAutoHoistOper.setLiftAutoAcc(Integer.toString(autoHoistOper.getLiftAutoAcc()));
        //升降自动减速时间
        handleAutoHoistOper.setLiftAutoDec(Integer.toString(autoHoistOper.getLiftAutoDec()));
        //升降手动速度
        handleAutoHoistOper.setLiftManualSpeed(Integer.toString(autoHoistOper.getLiftManualSpeed()));
        //升降手动加速时间
        handleAutoHoistOper.setLiftManualAcc(Integer.toString(autoHoistOper.getLiftManualAcc()));
        //升降手动减速时间
        handleAutoHoistOper.setLiftManualDec(Integer.toString(autoHoistOper.getLiftManualDec()));
        //输送线自动速度
        handleAutoHoistOper.setConveyorAutoSpeed(Integer.toString(autoHoistOper.getConveyorAutoSpeed()));
        //输送线自动加速时间
        handleAutoHoistOper.setConveyorAutoAcc(Integer.toString(autoHoistOper.getConveyorAutoAcc()));
        //输送线自动减速时间
        handleAutoHoistOper.setConveyorAutoDec(Integer.toString(autoHoistOper.getConveyorAutoDec()));
        //输送线手动速度
        handleAutoHoistOper.setConveyorManualSpeed(Integer.toString(autoHoistOper.getConveyorManualSpeed()));
        //输送线手动加速时间
        handleAutoHoistOper.setConveyorManualAcc(Integer.toString(autoHoistOper.getConveyorManualAcc()));
        //输送线手动减速时间
        handleAutoHoistOper.setConveyorManualDec(Integer.toString(autoHoistOper.getConveyorManualDec()));
        //自动升降机运行
        handleAutoHoistOper.setTaskAction(Integer.toString(autoHoistOper.getTaskAction()));
        //故障清除
        handleAutoHoistOper.setClearError(autoHoistOper.isClearError() ? "故障清除" : "无");
        //外形检测开启
        handleAutoHoistOper.setIsOpenShape(autoHoistOper.isOpenShape() ? "开启" : "关闭");
        //扫码故障灯
        handleAutoHoistOper.setIsOpenBcr(autoHoistOper.isOpenBcr() ? "打开" : "关闭");
        //超重灯
        handleAutoHoistOper.setIsOpenOverweight(autoHoistOper.isOpenOverweight() ? "打开" : "关闭");
        //系统急停
        handleAutoHoistOper.setStopState(autoHoistOper.isStopState() ? "急停" : "未急停");
        //系统手动模式/自动本地
        String mode = "未知";
        if (autoHoistOper.isControllerModeManual()) {
            mode = "手动";
        }
        if (autoHoistOper.isControllerModeAuto()) {
            mode = "自动";
        }
        handleAutoHoistOper.setControllerMode(mode);
        //手动上升
        handleAutoHoistOper.setManualUp(autoHoistOper.isManualUp() ? "运行中" : "未运行");
        //手动下降
        handleAutoHoistOper.setManualDown(autoHoistOper.isManualDown() ? "运行中" : "未运行");
        //手动输送线正转
        handleAutoHoistOper.setManualForward(autoHoistOper.isManualForward() ? "运行中" : "未运行");
        //手动输送线反转
        handleAutoHoistOper.setManualReverse(autoHoistOper.isManualReverse() ? "运行中" : "未运行");
        //故障复位
        handleAutoHoistOper.setClearError1(autoHoistOper.isClearError1() ? "有" : "无");
        //WCS可控=就绪/未就绪
        handleAutoHoistOper.setIsControl(autoHoistOper.isControl() ? "就绪" : "未就绪");
        //设备正在运行中
        handleAutoHoistOper.setDeviceState(autoHoistOper.isDeviceState() ? "运行中" : "未运行");
        //升降正在运行中
        handleAutoHoistOper.setElevatorState(autoHoistOper.isElevatorState() ? "运行中" : "未运行");
        //输送线正在运行
        handleAutoHoistOper.setConveyorState(autoHoistOper.isConveyorState() ? "运行中" : "未运行");
        //故障报警状态
        handleAutoHoistOper.setErrorState(autoHoistOper.isErrorState() ? "报警" : "正常");
        //上升极限
        handleAutoHoistOper.setRiseLimit(autoHoistOper.isRiseLimit() ? "超限" : "未超限");
        //下降极限
        handleAutoHoistOper.setDropLimit(autoHoistOper.isDropLimit() ? "超限" : "未超限");
        //上升到位
        handleAutoHoistOper.setRiseInPlace(autoHoistOper.isRiseInPlace() ? "到位" : "未到位");
        //下降到位
        handleAutoHoistOper.setDropInPlace(autoHoistOper.isDropInPlace() ? "到位" : "未到位");
        //输送线1方向限位
        handleAutoHoistOper.setLimit1(autoHoistOper.isLimit1() ? "超限" : "未超限");
        //输送线3方向限位
        handleAutoHoistOper.setLimit3(autoHoistOper.isLimit3() ? "超限" : "未超限");
        //输送线1到位
        handleAutoHoistOper.setInPlaceSignal1(autoHoistOper.isInPlaceSignal1() ? "到位" : "未到位");
        //输送线2到位
        handleAutoHoistOper.setInPlaceSignal2(autoHoistOper.isInPlaceSignal2() ? "到位" : "未到位");
        //故障码
        handleAutoHoistOper.setErrorInfo(Integer.toString(autoHoistOper.getErrorInfo()));
        //校准位
        handleAutoHoistOper.setCheckNo(Integer.toString(autoHoistOper.getCheckNo()));
        //当前设备类型
        handleAutoHoistOper.setCurrentDeviceType((autoHoistOper.getCurrentDeviceType() == 8 ? "自动升降机" : "未知"));
        return handleAutoHoistOper;
    }

    /**
     * 设置升降自动类型（初始化）
     */
    public void setDeviceType(FoldingOper foldingOper) throws IOException {
        foldingOper.setDeviceType();
    }

    /**
     * 设置升降自动类型（初始化）
     */
    public void setDeviceType(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setDeviceType();
    }
    /**
     * 设置移栽机类型（初始化）
     */
    public void setDeviceType(TransPlanter transPlanter) throws IOException {
        transPlanter.setDeviceType();
    }

    /**
     * 设置升降自动速度
     */
    public void autoHoistLiftAutoSpeed(Integer speed, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftAutoSpeed(speed);
    }

    /**
     * 设置升降自动加速时间
     */
    public void autoHoistLiftAutoAcc(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftAutoAcc(time);
    }

    /**
     * 设置升降自动减速时间
     */
    public void autoHoistLiftAutoDec(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftAutoDec(time);
    }

    /**
     * 设置升降手动速度
     */
    public void autoHoistLiftManualSpeed(Integer speed, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftManualSpeed(speed);
    }

    /**
     * 设置升降手动加速时间
     */
    public void autoHoistLiftManualAcc(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftManualAcc(time);
    }

    /**
     * 设置升降自动速度
     */
    public void autoHoistLiftManualDec(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setLiftManualDec(time);
    }

    /**
     * 设置输送线自动速度
     */
    public void autoHoistConveyorAutoSpeed(Integer speed, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorAutoSpeed(speed);
    }

    /**
     * 设置输送线自动加速时间
     */
    public void autoHoistConveyorAutoAcc(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorAutoAcc(time);
    }

    /**
     * 设置输送线自动减速时间
     */
    public void autoHoistConveyorAutoDec(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorAutoDec(time);
    }

    /**
     * 设置输送线手动速度
     */
    public void autoHoistConveyorManualSpeed(Integer speed, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorManualSpeed(speed);
    }

    /**
     * 设置输送线手动加速时间
     */
    public void autoHoistConveyorManualAcc(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorManualAcc(time);
    }

    /**
     * 设置输送线手动减速时间
     */
    public void autoHoistConveyorManualDec(Integer time, AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setConveyorManualDec(time);
    }

    /**
     * 平台升位移量
     */
    public void autoHoistRiseMovement(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setPlatformRiseMovement();
    }

    /**
     * 平台降位移量
     */
    public void autoHoistDropMovement(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setPlatformDropMovement();
    }

    /**
     * 平台上升
     */
    public void platformRise(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformRise();
    }

    /**
     * 平台下降
     */
    public void platformDrop(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformDrop();
    }

    /**
     * 正转入库
     */
    public void platformAutoForwardIn(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformForwardIn();
    }

    /**
     * 正转出库
     */
    public void platformAutoForwardOut(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformForwardOut();
    }

    /**
     * 反转入库
     */
    public void platformAutoReverseIn(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformReverseIn();
    }

    /**
     * 反转出库
     */
    public void platformAutoReverseOut(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.platformReverseOut();
    }

    /**
     * 自动升降机故障清除
     */
    @Override
    public void autoHoistClearError(AutoHoistOper autoHoistOper) throws IOException {
        autoHoistOper.setClearError();
    }

    /**
     * 设置升降自动类型（初始化）
     */
    public void setDeviceType(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.setDeviceType();
    }

    /**
     * 设置升降自动速度
     */
    @Override
    public void toothHoistLiftAutoSpeed(ToothHoistOper toothHoistOper, Integer speed) throws IOException {
        toothHoistOper.setLiftAutoSpeed(speed);
    }

    /**
     * 设置升降自动加速时间
     */
    @Override
    public void toothHoistLiftAutoAcc(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setLiftAutoAcc(time);
    }

    /**
     * 设置升降自动减速时间
     */
    @Override
    public void toothHoistLiftAutoDec(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setLiftAutoDec(time);
    }

    /**
     * 设置升降手动速度
     */
    @Override
    public void toothHoistLiftManualSpeed(ToothHoistOper toothHoistOper, Integer speed) throws IOException {
        toothHoistOper.setLiftManualSpeed(speed);
    }

    /**
     * 设置升降手动加速时间
     */
    @Override
    public void toothHoistLiftManualAcc(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setLiftManualAcc(time);
    }

    /**
     * 设置升降自动速度
     */
    @Override
    public void toothHoistLiftManualDec(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setLiftManualDec(time);
    }

    /**
     * 设置输送线自动速度
     */
    @Override
    public void toothHoistConveyorAutoSpeed(ToothHoistOper toothHoistOper, Integer speed) throws IOException {
        toothHoistOper.setConveyorAutoSpeed(speed);
    }

    /**
     * 设置输送线自动加速时间
     */
    @Override
    public void toothHoistConveyorAutoAcc(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setConveyorAutoAcc(time);
    }

    /**
     * 设置输送线自动减速时间
     */
    @Override
    public void toothHoistConveyorAutoDec(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setConveyorAutoDec(time);
    }

    /**
     * 设置输送线手动速度
     */
    @Override
    public void toothHoistConveyorManualSpeed(ToothHoistOper toothHoistOper, Integer speed) throws IOException {
        toothHoistOper.setConveyorManualSpeed(speed);
    }

    /**
     * 设置输送线手动加速时间
     */
    @Override
    public void toothHoistConveyorManualAcc(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setConveyorManualAcc(time);
    }

    /**
     * 设置输送线手动减速时间
     */
    @Override
    public void toothHoistConveyorManualDec(ToothHoistOper toothHoistOper, Integer time) throws IOException {
        toothHoistOper.setConveyorManualDec(time);
    }

    /**
     * 平台升位移量
     */
    @Override
    public void toothHoistRiseMovement(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.setPlatformRiseMovement();
    }

    /**
     * 平台降位移量
     */
    @Override
    public void toothHoistDropMovement(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.setPlatformDropMovement();
    }

    /**
     * 平台上升
     */
    @Override
    public void platformRise(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformRise();
    }

    /**
     * 平台下降
     */
    @Override
    public void platformDrop(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformDrop();
    }

    /**
     * 正转入库
     */
    @Override
    public void platformToothForwardIn(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformForwardIn();
    }

    /**
     * 正转出库
     */
    @Override
    public void platformToothForwardOut(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformForwardOut();
    }

    /**
     * 反转入库
     */
    @Override
    public void platformToothReverseIn(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformReverseIn();
    }

    /**
     * 反转出库
     */
    @Override
    public void platformToothReverseOut(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.platformReverseOut();
    }

    /**
     * 自动升降机故障清除
     */
    @Override
    public void toothHoistClearError(ToothHoistOper toothHoistOper) throws IOException {
        toothHoistOper.setClearError();
    }

    /**
     * 自动门信息
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleAutoDoor plcAutoDoorDevice(String deviceName) {
        AutomaticDoorOper automaticDoorOper = (AutomaticDoorOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleAutoDoor autoDoor = new HandleAutoDoor();
        autoDoor.setDeviceName(deviceName);
        if (automaticDoorOper == null) {
            autoDoor.setReadyState("离线");
            return autoDoor;
        }
        autoDoor.setReadyState("在线");
        autoDoor.setIsAutoDoorOpen(automaticDoorOper.isOpen() ? "开启到位" : "未到位");
        autoDoor.setIsAutoDoorClose(automaticDoorOper.isClose() ? "关闭到位" : "未到位");
        autoDoor.setIsAutoDoorError(automaticDoorOper.isError() ? "故障" : "无故障");
        return autoDoor;
    }

    /**
     * 自动门信息2
     *
     * @param deviceName
     * @return
     */
    @Override
    public HandleAutoDoor2 plcAutoDoorDevice2(String deviceName) {
        SingleAutoDoor singleAutoDoor = (SingleAutoDoor) Plc.deviceBaseNameMap.get(deviceName);
        HandleAutoDoor2 autoDoor2 = new HandleAutoDoor2();
        autoDoor2.setDeviceName(deviceName);
        if (singleAutoDoor == null) {
            autoDoor2.setReadyState("离线");
            return autoDoor2;
        }
        autoDoor2.setReadyState(singleAutoDoor.getPlc().getPlcStatus() == Network.ON_LINE ? "在线" : "离线");
        autoDoor2.setIsAutoDoorOpen(singleAutoDoor.isOpen() ? "开启到位" : "未到位");
        autoDoor2.setIsAutoDoorClose(singleAutoDoor.isClose() ? "关闭到位" : "未到位");
        autoDoor2.setIsAutoDoorError(singleAutoDoor.isError() ? "故障" : "无故障");
        autoDoor2.setRunIng(singleAutoDoor.runIng() ? "运行" : "未运行");
        autoDoor2.setOverTime(singleAutoDoor.overTime() ? "运行超时" : "运行未超时");
        autoDoor2.setIsLock(singleAutoDoor.isLock() ? "已锁定" : "未锁定");
        autoDoor2.setDeviceDes(singleAutoDoor.getStatus());
        return autoDoor2;
    }

    @Override
    public HandleSystem plcSystemDevice(String deviceName) {
        SystemOper systemOper = (SystemOper) Plc.deviceBaseNameMap.get(deviceName);
        HandleSystem handleSystem = new HandleSystem();
        handleSystem.setDeviceName(systemOper.getDeviceName());
        if (systemOper == null) {
            handleSystem.setReadyState("离线");
            return handleSystem;
        }
        //设备编号
        handleSystem.setDeviceNo(Integer.toString(systemOper.getDeviceNum()));
        //读取完成信号
        handleSystem.setReadCompletionSignal(systemOper.getReadCompletionSignal() ? "完成" : "无效");
        //数据合格
        handleSystem.setDataQualified(systemOper.getDataQualified() == 0 ? "无效" : (systemOper.getDataQualified() == 1 ? "合格" : "不合格"));
        //工位编号
        handleSystem.setStationNo(Integer.toString(systemOper.getStationNo()));
        //运转方向
        handleSystem.setRunDirection(systemOper.getRunDirection() == 0 ? "停止" : (systemOper.getRunDirection() == 1 ? "入库" : "出库"));
        //托盘号
        handleSystem.setPalletNo(Integer.toString(systemOper.getPalletNo()));
        //起始工位编号
        handleSystem.setStartStationNo(Integer.toString(systemOper.getStartStationNo()));
        //目的工位编号
        handleSystem.setEndStationNo(Integer.toString(systemOper.getEndStationNo()));
        //自动门编号
        handleSystem.setAutoDoor(Integer.toString(systemOper.getAutoDoor()));
        //开启自动门
        handleSystem.setOpenAutoDoor(systemOper.getOpenAutoDoor() == 0 ? "无效" : (systemOper.getOpenAutoDoor() == 1 ? "开启" : "关闭"));
        handleSystem.setSystemModel(systemOper.isSystemModel() ? "手动" : "非手动");
        handleSystem.setAutoDistance(systemOper.isAutoDistance() ? "远程" : "非远程");
        handleSystem.setAutoLocality(systemOper.isAutoLocality() ? "本地" : "非本地");
        handleSystem.setSystemStop(systemOper.isSystemStop() ? "急停中" : "未急停");
        handleSystem.setConveyCrashStop1(systemOper.isConveyCrashStop1() ? "急停中" : "未急停");
        handleSystem.setConveyCrashStop2(systemOper.isConveyCrashStop2() ? "急停中" : "未急停");
        handleSystem.setConveyCrashStop3(systemOper.isConveyCrashStop3() ? "急停中" : "未急停");
        handleSystem.setCheckBit("" + systemOper.getCheckBit());
        handleSystem.setReadyState("在线");
        handleSystem.setDeviceName(deviceName);
        return handleSystem;
    }

    /**
     * 通过坐标获取设备
     *
     * @param coord
     * @return
     */
    @Override
    public List<PlcDeviceDB> getPlcByLocation(Coord coord) {
        LambdaQueryWrapper<PlcDeviceDB> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(PlcDeviceDB::getDeviceLocation, coord.toString());
        return plcdevicedbMapper.selectList(lambdaQueryWrapper);
    }


    /**
     * 获取提升机设备
     *
     * @param plcDeviceType
     * @param coord
     * @return
     */
    public PlcDeviceDB getLifterDeviceDB(int plcDeviceType, Coord coord) {
        LambdaQueryWrapper<PlcDeviceDB> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(PlcDeviceDB::getDeviceLocation, coord.toString()).eq(PlcDeviceDB::getDeviceType, plcDeviceType);
        PlcDeviceDB plcDeviceDB = plcdevicedbMapper.selectOne(lambdaQueryWrapper);
        if (plcDeviceDB == null) {
            throw new RuntimeException("找不到提升机,提升机配置错误,请检查提升机配置信息");
        }
        return plcDeviceDB;
    }


    /**
     * 设置横移自动类型（初始化）
     */
    public void setDeviceType(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setDeviceType();
    }

    /**
     * 设置横移自动速度
     */
    public void traverseAutoSpeed(AutoTraversingOper autoTraversingOper, Integer speed) throws IOException {
        autoTraversingOper.setTraverseAutoSpeed(speed);
    }

    /**
     * 设置横移自动加速时间
     */
    public void traverseAutoAcc(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setTraverseAutoAcc(time);
    }

    /**
     * 设置横移自动减速时间
     */
    public void traverseAutoDec(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setTraverseAutoDec(time);
    }

    /**
     * 设置横移手动速度
     */
    public void traverseManualSpeed(AutoTraversingOper autoTraversingOper, Integer speed) throws IOException {
        autoTraversingOper.setTraverseManualSpeed(speed);
    }

    /**
     * 设置横移手动加速时间
     */
    public void traverseManualAcc(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setTraverseManualAcc(time);
    }

    /**
     * 设置横移手动减速时间
     */
    public void traverseManualDec(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setTraverseManualDec(time);
    }

    /**
     * 设置输送线自动速度
     */
    public void traverseConveyorAutoSpeed(AutoTraversingOper autoTraversingOper, Integer speed) throws IOException {
        autoTraversingOper.setConveyorAutoSpeed(speed);
    }

    /**
     * 设置输送线自动加速时间
     */
    public void traverseConveyorAutoAcc(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setConveyorAutoAcc(time);
    }

    /**
     * 设置输送线自动减速时间
     */
    public void traverseConveyorAutoDec(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setConveyorAutoDec(time);
    }

    /**
     * 设置输送线手动速度
     */
    public void traverseConveyorManualSpeed(AutoTraversingOper autoTraversingOper, Integer speed) throws IOException {
        autoTraversingOper.setConveyorManualSpeed(speed);
    }

    /**
     * 设置输送线手动加速时间
     */
    public void traverseConveyorManualAcc(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setConveyorManualAcc(time);
    }

    /**
     * 设置输送线手动减速时间
     */
    public void traverseConveyorManualDec(AutoTraversingOper autoTraversingOper, Integer time) throws IOException {
        autoTraversingOper.setConveyorManualDec(time);
    }
    /**
     * 打开外形检测
     */
    public void setOpenShape(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.openShape();
    }

    /**
     * 关闭外形检测
     */
    public void setCloseShape(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.closeShape();
    }

    /**
     * 设置输送线自动速度
     */
    public void shapeConveyorAutoSpeed(ShapeConveyorOper shapeConveyorOper, Integer speed) throws IOException {
        shapeConveyorOper.setConveyorAutoSpeed(speed);
    }

    /**
     * 设置输送线自动加速时间
     */
    public void shapeConveyorAutoAcc(ShapeConveyorOper shapeConveyorOper, Integer time) throws IOException {
        shapeConveyorOper.setConveyorAutoAcc(time);
    }

    /**
     * 设置输送线自动减速时间
     */
    public void shapeConveyorAutoDec(ShapeConveyorOper shapeConveyorOper, Integer time) throws IOException {
        shapeConveyorOper.setConveyorAutoDec(time);
    }

    /**
     * 设置输送线手动速度
     */
    public void shapeConveyorManualSpeed(ShapeConveyorOper shapeConveyorOper, Integer speed) throws IOException {
        shapeConveyorOper.setConveyorManualSpeed(speed);
    }

    /**
     * 设置输送线手动加速时间
     */
    public void shapeConveyorManualAcc(ShapeConveyorOper shapeConveyorOper, Integer time) throws IOException {
        shapeConveyorOper.setConveyorManualAcc(time);
    }

    /**
     * 设置输送线手动减速时间
     */
    public void shapeConveyorManualDec(ShapeConveyorOper shapeConveyorOper, Integer time) throws IOException {
        shapeConveyorOper.setConveyorManualDec(time);
    }

    /**
     * 反转入库
     */
    public void shapeConveyorForwardIn(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.IN);
    }

    /**
     * 反转入库
     */
    public void shapeConveyorForwardOut(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.OUT);
    }

    /**
     * 反转出库
     */
    public void shapeConveyorReverseIn(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.IN);
    }

    /**
     * 反转出库
     */
    public void shapeConveyorReverseOut(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.OUT);
    }

    /**
     * 自动升降机故障清除
     */
    public void shapeConveyorClearError(ShapeConveyorOper shapeConveyorOper) throws IOException {
        shapeConveyorOper.clearError();
    }

    /**
     * 设置输送线自动类型（初始化）
     */
    public void setDeviceType(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.setDeviceType();
    }

    /**
     * 单体输送线打开扫码故障灯
     */
    public void openScannerError(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.setScanError();
    }

    /**
     * 单体输送线关闭扫码故障灯
     */
    public void closeScannerError(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.clearScanError();
    }

    /**
     * 单体输送线打开超重灯
     */
    public void openOverweight(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.setWeightError();
    }

    /**
     * 单体输送线关闭超重灯
     */
    public void closeOverweight(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.clearWeightError();
    }

    /**
     * 单体输送线打开超重灯
     */
    public void openAlarmlamp(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.setNoTaskError();
    }

    /**
     * 单体输送线关闭超重灯
     */
    public void closeAlarmlamp(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.clearNoTaskError();
    }

    /**
     * 单体输送线关闭超重灯
     */
    public void clearInTask(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.clearError();
    }

    /**
     * 设置输送线自动速度
     */
    public void monomerConveyorAutoSpeed(MonomerConveyorOper monomerConveyorOper, Integer speed) throws IOException {
        monomerConveyorOper.setConveyorAutoSpeed(speed);
    }

    /**
     * 设置输送线自动加速时间
     */
    public void monomerConveyorAutoAcc(MonomerConveyorOper monomerConveyorOper, Integer time) throws IOException {
        monomerConveyorOper.setConveyorAutoAcc(time);
    }

    /**
     * 设置输送线自动减速时间
     */
    public void monomerConveyorAutoDec(MonomerConveyorOper monomerConveyorOper, Integer time) throws IOException {
        monomerConveyorOper.setConveyorAutoDec(time);
    }

    /**
     * 设置输送线手动速度
     */
    public void monomerConveyorManualSpeed(MonomerConveyorOper monomerConveyorOper, Integer speed) throws IOException {
        monomerConveyorOper.setConveyorManualSpeed(speed);
    }

    /**
     * 设置输送线手动加速时间
     */
    public void monomerConveyorManualAcc(MonomerConveyorOper monomerConveyorOper, Integer time) throws IOException {
        monomerConveyorOper.setConveyorManualAcc(time);
    }

    /**
     * 设置输送线手动减速时间
     */
    public void monomerConveyorManualDec(MonomerConveyorOper monomerConveyorOper, Integer time) throws IOException {
        monomerConveyorOper.setConveyorManualDec(time);
    }

    /**
     * 平台升位移量
     */
    public void monomerConveyorRiseMovement(MonomerConveyorOper monomerConveyorOper) throws IOException {
//        monomerConveyorOper.setPlatformRiseMovement();
    }

    /**
     * 平台降位移量
     */
    public void monomerConveyorDropMovement(MonomerConveyorOper monomerConveyorOper) throws IOException {
//        monomerConveyorOper.setPlatformDropMovement();
    }

    /**
     * 单体输送线正转
     */
    public void singleConveyorForward(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setConveyorForward();
    }

    /**
     * 单体输送线反转
     */
    public void singleConveyorReverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setConveyorReverse();
    }

    /**
     * 单体输送线反转
     */
    public void singleConveyorStop(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setConveyorStop();
    }
    /**
     * 单体输送线正转
     */
    public void conveyorForwardIn(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.IN);
    }

    /**
     * 单体输送线反转
     */
    public void conveyorReverseIn(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.IN);
    }

    /**
     * 单体输送线正转
     */
    public void conveyorForwardOut(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.OUT);
    }

    /**
     * 单体输送线反转
     */
    public void conveyorReverseOut(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.OUT);
    }

    /**
     * 正转入库
     */
    public void door1Forward(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.OUT);
    }

    /**
     * 正转出库
     */
    public void door1Reverse(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.OUT);
    }

    /**
     * 反转入库
     */
    public void door3Forward(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.IN, ConveryTaskType.IN);
    }

    /**
     * 反转出库
     */
    public void door3Reverse(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.converyRun(SingleConveryRunType.CONVERY, Direction.OUT, ConveryTaskType.IN);
    }


    /**
     * 自动门1正转
     */
    public void door1Forward(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setDoor1Forward();
    }

    /**
     * 自动门1反转
     */
    public void door1Reverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setDoor1Reverse();
    }

    /**
     * 自动门3正转
     */
    public void door3Forward(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setDoor3Forward();
    }

    /**
     * 自动门3反转
     */
    public void door3Reverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setDoor3Reverse();
    }

    /**
     * 平台左横移
     */
    public void platformLeftTraverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.platformLeft();
    }

    /**
     * 平台右横移
     */
    public void platformRightTraverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.platformRight();
    }

    /**
     * 平台原位
     */
    public void platformInSituTraverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.platformInSitu();
    }

    /**
     * 横移机输送线正转
     */
    public void traverseConveyorForward(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.traverseConveyorForward();
    }
    /**
     * 横移机输送线反转
     */
    public void traverseConveyorReverse(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.traverseConveyorReverse();
    }

    /**
     * 自动升降机故障清除
     */
    public void monomerConveyorClearError(MonomerConveyorOper monomerConveyorOper) throws IOException {
        monomerConveyorOper.clearError();
    }
    /**
     * 自动升降机故障清除
     */
    public void traverseClearError(AutoTraversingOper autoTraversingOper) throws IOException {
        autoTraversingOper.setClearError();
    }
    @Override
    public List<PlcDeviceDB> selectPlcDevByPlcId(Integer plcId) {
        QueryWrapper<PlcDeviceDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(PlcDeviceDB::getPlcId, plcId);
        return list(queryWrapper);
    }



    /**
     * 移裁机信息
     *
     * @param deviceId
     * @return
     */
    public HandleTransP plcTransPDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        TransPlanter transPlanter = (TransPlanter) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleTransP htp = new HandleTransP();
        htp.setDeviceId(deviceId);
        htp.setDeviceName(plcDeviceDB.getDeviceName());
        if (transPlanter == null) {
            htp.setReadyState("离线");
            return htp;
        }
        htp.setReadyState(transPlanter.getPlc().getPlcStatus().getDescription());
        //设备类型
        htp.setDeviceType(transPlanter.getCurrentDeviceType() == 6 ? "移裁机" : "未知");
        //设备位移量
        htp.setMovement(Integer.toString(transPlanter.getMovement()));
        //升降自动速度
        htp.setLiftAutoSpeed(Integer.toString(transPlanter.getLiftAutoSpeed()));
        //升降自动加速时间
        htp.setLiftAutoAcc(Integer.toString(transPlanter.getLiftAutoAcc()));
        //升降自动减速时间
        htp.setLiftAutoDec(Integer.toString(transPlanter.getLiftAutoDec()));
        //升降手动速度
        htp.setLiftManualSpeed(Integer.toString(transPlanter.getLiftManualSpeed()));
        //升降手动加速时间
        htp.setLiftManualAcc(Integer.toString(transPlanter.getLiftManualAcc()));
        //升降手动减速时间
        htp.setLiftManualDec(Integer.toString(transPlanter.getLiftManualDec()));
        //输送线自动速度
        htp.setConveyorAutoSpeed(Integer.toString(transPlanter.getConveyorAutoSpeed()));
        //输送线自动加速时间
        htp.setConveyorAutoAcc(Integer.toString(transPlanter.getConveyorAutoAcc()));
        //输送线自动减速时间
        htp.setConveyorAutoDec(Integer.toString(transPlanter.getConveyorAutoDec()));
        //输送线手动速度
        htp.setConveyorManualSpeed(Integer.toString(transPlanter.getConveyorManualSpeed()));
        //输送线手动加速时间
        htp.setConveyorManualAcc(Integer.toString(transPlanter.getConveyorManualAcc()));
        //输送线手动减速时间
        htp.setConveyorManualDec(Integer.toString(transPlanter.getConveyorManualDec()));
        //移裁升降机
        htp.setTaskAction(Integer.toString(transPlanter.getTaskAction()));
        //故障清除
        htp.setClearError(transPlanter.isClearError() ? "故障清除" : "无");
        //外形检测开启
        htp.setIsOpenShape(transPlanter.isOpenShape() ? "开启" : "关闭");
        //扫码故障灯
        htp.setIsOpenBcr(transPlanter.isOpenBcr() ? "打开" : "关闭");
        //超重灯
        htp.setIsOpenOverweight(transPlanter.isOpenOverweight() ? "打开" : "关闭");
        //系统急停
        htp.setStopState(transPlanter.isStopState() ? "急停" : "未急停");
        //系统手动模式/自动本地
        String mode = "未知";
        if (transPlanter.isControllerModeManual()) {
            mode = "手动";
        }
        if (transPlanter.isControllerModeAuto()) {
            mode = "自动";
        }
        htp.setControllerMode(mode);
        //手动上升
        htp.setManualUp(transPlanter.isManualUp() ? "运行中" : "未运行");
        //手动下降
        htp.setManualDown(transPlanter.isManualDown() ? "运行中" : "未运行");
        //手动输送线正转
        htp.setManualForward(transPlanter.isManualForward() ? "运行中" : "未运行");
        //手动输送线反转
        htp.setManualReverse(transPlanter.isManualReverse() ? "运行中" : "未运行");
        //故障复位
        htp.setClearError1(transPlanter.isClearError1() ? "有" : "无");
        //WCS可控=就绪/未就绪
        htp.setIsControl(transPlanter.isControl() ? "就绪" : "未就绪");
        //设备正在运行中
        htp.setDeviceState(transPlanter.isRunning() ? "运行中" : "未运行");
        //升降正在运行中
        htp.setElevatorState(transPlanter.isElevatorState() ? "运行中" : "未运行");
        //输送线正在运行
        htp.setConveyorState(transPlanter.isConveyorState() ? "运行中" : "未运行");
        //故障报警状态
        htp.setErrorState(transPlanter.isErrorState() ? "故障" : "正常");
        //镜反光电1
        htp.setSignal1(transPlanter.isInCargoSignalValid() ? "到位" : "未到位");
        //镜反光电2
        htp.setSignal2(transPlanter.isOutCargoSignalValid() ? "到位" : "未到位");
        //移裁顶升上到位（预留）
        htp.setRiseInPlace(transPlanter.isRiseInPlace() ? "到位" : "未到位");
        //移裁顶升下到位（预留）
        htp.setDropInPlace(transPlanter.isDropInPlace() ? "到位" : "未到位");
        //故障码
        htp.setErrorInfo(Integer.toString(transPlanter.getErrorInfo()));
        //校准位
        htp.setCheckNo(Integer.toString(transPlanter.getCheckNo()));
        //设备任务信息
        htp.setDeviceDes(transPlanter.getStatus());
        //当前设备类型
        htp.setCurrentDeviceType(SinglePlcDeviceType.parseValue(transPlanter.getCurrentDeviceType()).toString());
        //任务号
        htp.setTaskNo(transPlanter.getTaskNo());
        htp.setStartNo(transPlanter.getTaskStartLocation());
        htp.setEndNo(transPlanter.getTaskEndLocation());

        return htp;
    }

    @Override
    public HandleWeightOper plcWeightDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        WeightOper weightOper = (WeightOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleWeightOper handleWeight = new HandleWeightOper();
        handleWeight.setDeviceName(plcDeviceDB.getDeviceName());
        if (weightOper == null) {
            handleWeight.setReadyState("离线");
            return handleWeight;
        }
        handleWeight.setReadyState("在线");
        handleWeight.setWeightFlag(weightOper.isCanWeightRead() ? "数据可读" : "数据不可读");
        handleWeight.setWeightData(((double) Long.parseLong("" + weightOper.getWeightData())) / 10);
        return handleWeight;
    }

    @Override
    public HandleLifterSystem lifterSystemDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        LifterSystemOper lifterSystemOper = (LifterSystemOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleLifterSystem handleLifterSystem = new HandleLifterSystem();
        handleLifterSystem.setDeviceName(plcDeviceDB.getDeviceName());
        if (lifterSystemOper == null) {
            handleLifterSystem.setReadyState("离线");
            return handleLifterSystem;
        }
        handleLifterSystem.setReadyState(lifterSystemOper.getPlc().getPlcStatus().getDescription());
        handleLifterSystem.setCheckNo(lifterSystemOper.getCheck());
        handleLifterSystem.setMainStation(lifterSystemOper.isMainStation() ? "主站" : "非主站");
        return handleLifterSystem;
    }


    @Override
    public HandleLifterStation lifterStationDevice(Integer deviceId) {
        PlcDeviceDB plcDeviceDB = getPlcDevById(deviceId);
        LifterStationOper lifterStationOper = (LifterStationOper) Plc.deviceBaseNameMap.get(plcDeviceDB.getDeviceName());
        HandleLifterStation handleLifterStation = new HandleLifterStation();
        handleLifterStation.setDeviceName(plcDeviceDB.getDeviceName());
        if (lifterStationOper == null) {
            handleLifterStation.setReadyState("离线");
            return handleLifterStation;
        }
        handleLifterStation.setReadyState(lifterStationOper.getPlc().getPlcStatus().getDescription());
        handleLifterStation.setAutoMode(lifterStationOper.isAutoMode() ? "是" : "否");
        handleLifterStation.setEmergencyStop(lifterStationOper.isEmergencyStop() ? "急停" : "非急停");
        handleLifterStation.setError(lifterStationOper.isError() ? "是" : "否");
        handleLifterStation.setManualMode(lifterStationOper.isManualMode() ? "是" : "否");
        handleLifterStation.setMarginSignal(lifterStationOper.isMarginSignal() ? "有信号" : "无信号");
        handleLifterStation.setNearSignal(lifterStationOper.isNearSignal() ? "有信号" : "无信号");
        handleLifterStation.setRemoteSignal(lifterStationOper.isRemoteSignal() ? "有信号" : "无信号");
        handleLifterStation.setRunning(lifterStationOper.isRunning() ? "运行中" : "未运行");
        return handleLifterStation;
    }

    /**
     * 单体拆叠盘机
     * @param foldingOper
     * @param speed
     * @throws IOException
     */
    @Override
    public void foldingMachineAutoSpeed(FoldingOper foldingOper, Integer speed) throws IOException {
        foldingOper.setLiftAutoSpeed(speed);
    }

    @Override
    public void foldingMachineAutoAcc(FoldingOper foldingOper, Integer time) throws IOException {
        foldingOper.setLiftAutoAcc(time);
    }

    @Override
    public void foldingMachineAutoDec(FoldingOper foldingOper, Integer time) throws IOException {
        foldingOper.setLiftAutoDec(time);
    }

    @Override
    public void foldingMachineManualSpeed(FoldingOper foldingOper, Integer speed) throws IOException {
        foldingOper.setLiftManualSpeed(speed);
    }

    @Override
    public void foldingMachineManualAcc(FoldingOper foldingOper, Integer time) throws IOException {
        foldingOper.setLiftManualAcc(time);
    }

    @Override
    public void foldingMachineManualDec(FoldingOper foldingOper, Integer time) throws IOException {
        foldingOper.setLiftManualDec(time);
    }

    @Override
    public void foldingMachineManualUp(FoldingOper foldingOper) throws IOException {
        foldingOper.manualUp();
    }

    @Override
    public void foldingMachineManualDown(FoldingOper foldingOper) throws IOException {
        foldingOper.manualDown();
    }

    @Override
    public void foldingMachineReachInPlace(FoldingOper foldingOper) throws IOException {
        foldingOper.manualPush();
    }

    @Override
    public void foldingMachineShrinkInPlace(FoldingOper foldingOper) throws IOException {
        foldingOper.manualRetract();
    }

    @Override
    public void foldingMachineDismantlePallet(FoldingOper foldingOper) throws IOException {
        foldingOper.setActionTask(FoldingMachineAction.REMOVE_PALLET.getValue());
    }

    @Override
    public void foldingMachineFoldPallet(FoldingOper foldingOper) throws IOException {
        foldingOper.setActionTask(FoldingMachineAction.STACK_PALLET.getValue());
    }

    @Override
    public void foldingMachineDismantleAllPallet(FoldingOper foldingOper) throws IOException {
        foldingOper.setActionTask(FoldingMachineAction.ALL_OUT.getValue());
    }

    @Override
    public void foldingMachineFoldAllPallet(FoldingOper foldingOper) throws IOException {
        foldingOper.setActionTask(FoldingMachineAction.ALL_IN.getValue());
    }

    @Override
    public void setClearError(FoldingOper foldingOper) throws IOException {
        foldingOper.setClearError();
    }


}
